/**
 * TODO: 演示代码 to be removed
 */
import request from '@/utils/request';

interface IGetRoleListParams {
  name?: string;
  tag?: string;
  status?: number;
  currPage?: number;
  pageSize?: number;
}

export interface IRoleItem {
  roleCode: string;
  roleName: string;
  roleDescribe: string;
  ownerId: string;
  updateTime: string;
  status: number;
}

export default {
  async getUserList() {
    await delay(1000);
    return {
      total: 6,
      list: [
        {
          id: 1,
          name: 'facebook/react',
          description: 'A declarative, efficient, and flexible JavaScript library for building user interfaces',
          logo: 'https://avatars3.githubusercontent.com/u/69631',
        },
        {
          id: 2,
          name: 'vuejs/vue',
          description:
            'Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web. ',
          logo: 'https://avatars1.githubusercontent.com/u/6128107',
        },
        {
          id: 3,
          name: 'angular/angular',
          description: 'One framework. Mobile & desktop. ',
          logo: 'https://avatars3.githubusercontent.com/u/139426',
        },
        {
          id: 4,
          name: 'nuxt/nuxt.js',
          description: 'The Vue.js Framework',
          logo: 'https://avatars2.githubusercontent.com/u/23360933',
        },
        {
          id: 5,
          name: 'zeit/next.js',
          description: 'The React Framework',
          logo: 'https://avatars0.githubusercontent.com/u/14985020',
        },
        {
          id: 6,
          name: 'ice-lab/ice.js',
          description: 'A universal framework based on React.js.',
          logo: 'https://avatars1.githubusercontent.com/u/1961952',
        },
      ],
    };
  },
  async getRoleList(params: IGetRoleListParams) {
    const res = await request
      .post('/abi-cloud-middle-platform-user-service/console/role/page-list', params)
      .catch(() => null);
    return {
      total: res?.data?.totalCount || 0,
      list: res?.data?.list || [],
    };
  },
};

function delay(timeout?: number | undefined, ...args: any[]) {
  return new Promise((resolve) => setTimeout(resolve, timeout, args));
}

export const aplanQuery = async (params: any): Promise<any> => {
  const api = '/abi-cloud-beesforce-morning-meeting/api/admin/aplan/query';
  const result: IAPIResponse<{ records: any; total: number }> | null = await request.doPost(api, params).catch();
  return {
    list: result?.data?.records ?? [],
    total: result?.data?.total ?? 0,
  };
};
